//
//  XCSingerHeaderView.m
//  TTLestening
//
//  Created by dllo on 16/3/25.
//  Copyright © 2016年 dilo. All rights reserved.
//

#import "XCSingerHeaderView.h"
#import "XCModelForSingerHeader.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "Masonry.h"
#define WIDGHTT [UIScreen mainScreen].bounds.size.width / 375
#define HEIGHTT [UIScreen mainScreen].bounds.size.height / 667

#define WIDGHT  self.frame.size.width
#define HEIGHT  self.frame.size.height


@interface XCSingerHeaderView ()



@end

@implementation XCSingerHeaderView

-(instancetype)initWithFrame:(CGRect)frame model:(XCModelForSingerHeader *)model {

    self = [super initWithFrame:frame];
    
    if (self) {
       // NSLog(@"111111");
        self.model = model;
        [self createSubview];
    }
    
    return self;
}


- (instancetype)initWithFrame:(CGRect)frame passModelForHot:(XCModelForSingerHeader *)model {
    
    self = [super initWithFrame:frame];
    
    if (self) {
       // NSLog(@"222222");
        self.model = model;
        [self createSubviewT];
        
//        NSLog(@"%@", [model.image objectForKey:@"pic"]);
        
    }
    
    return self;
    
}

- (void)createSubviewT {
    
    self.headerImage = [[UIImageView alloc] init];
    [self addSubview:self.headerImage];
    self.headerImage.backgroundColor = [UIColor clearColor];
    
    [self.headerImage mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.equalTo(self);
        
    }];
    
    [self.headerImage sd_setImageWithURL:[NSURL URLWithString:[self.model.image objectForKey:@"pic"]]];

   // NSLog(@"%@", [self.model.image objectForKey:@"pic"]);
    
    self.labelForName = [[UILabel alloc] init];
    [self addSubview:self.labelForName];
    
    [self.labelForName mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(self.headerImage.mas_centerY).multipliedBy(3. / 2.);
        make.left.mas_equalTo(self.headerImage).equalTo(@(20 * WIDGHTT));
        make.width.mas_equalTo(WIDGHT - 40 * WIDGHTT);
        make.height.mas_equalTo(self.labelForName.mas_width).multipliedBy(1. / 6.);
        
    }];
    // self.labelForName.backgroundColor = [UIColor redColor];
    self.labelForName.text = self.model.title;
    self.labelForName.textColor = [UIColor whiteColor];
    self.labelForName.font = [UIFont boldSystemFontOfSize:18];
    
    self.imageForLike = [[UIImageView alloc] init];
    [self addSubview:self.imageForLike];
    
    [self.imageForLike mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.headerImage).equalTo(@(20 * WIDGHTT));
        make.top.mas_equalTo(self.labelForName.mas_bottom).equalTo (@(5 * HEIGHTT));
        make.width.mas_equalTo(20 * WIDGHTT);
        make.height.mas_equalTo(self.imageForLike.mas_width).multipliedBy(1. / 1.);
        
    }];
    self.imageForLike.image = [UIImage imageNamed:@"iconfont-xin-1"];
    
    self.labelForNumber = [[UILabel alloc] init];
    [self addSubview:self.labelForNumber];
    self.labelForNumber.textColor = [UIColor whiteColor];
    self.labelForNumber.font = [UIFont boldSystemFontOfSize:16];
    
    [self.labelForNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.imageForLike.mas_right).equalTo(@(5 * WIDGHTT));
        make.centerY.equalTo(self.imageForLike.mas_centerY);
        make.width.mas_equalTo(50 * WIDGHTT);
        make.height.mas_equalTo(self.imageForLike.mas_width).multipliedBy(1. / 1.);
        
        
    }];
    
    
        self.labelForNumber.text = [NSString stringWithFormat:@"%ld", (long)self.model.favorite_count];
            
    self.imageForComment = [[UIImageView alloc] init];
    [self addSubview:self.imageForComment];
    
    [self.imageForComment mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.labelForNumber.mas_right).equalTo(@(10 * WIDGHTT));
        make.centerY.equalTo(self.imageForLike.mas_centerY);
        make.width.mas_equalTo(20 * WIDGHTT);
        make.height.mas_equalTo(self.imageForLike.mas_width).multipliedBy(1. / 1.);
    }];
    
    self.imageForComment.image = [UIImage imageNamed:@"iconfont-pinglun01"];
    
    self.labelForComment = [[UILabel alloc] init];
    [self addSubview:self.labelForComment];
    
    [self.labelForComment mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.imageForComment.mas_right).equalTo(@(5 * WIDGHTT));
        make.centerY.equalTo(self.imageForLike.mas_centerY);
        make.width.mas_equalTo(50 * WIDGHTT);
        make.height.mas_equalTo(self.imageForLike.mas_width).multipliedBy(1. / 1.);
        
    }];
    
    
    self.labelForComment.textColor = [UIColor whiteColor];
    self.labelForComment.font = [UIFont boldSystemFontOfSize:16];

    
    
    self.labelForComment.text = [NSString stringWithFormat:@"%ld", (long)self.model.comment_count];
     

}


- (void)createSubview {

    self.headerImage = [[UIImageView alloc] init];
    [self addSubview:self.headerImage];
    self.headerImage.backgroundColor = [UIColor clearColor];
    
    [self.headerImage mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.edges.equalTo(self);
        
    }];
    
    [self.headerImage sd_setImageWithURL:[NSURL URLWithString:self.model.picUrl]];
    
    self.labelForName = [[UILabel alloc] init];
    [self addSubview:self.labelForName];
    
    [self.labelForName mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.equalTo(self.headerImage.mas_centerY).multipliedBy(3. / 2.);
        make.left.mas_equalTo(self.headerImage).equalTo(@(20 * WIDGHTT));
        make.width.mas_equalTo(150 * WIDGHTT);
        make.height.mas_equalTo(self.labelForName.mas_width).multipliedBy(1. / 6.);
    
    }];
   // self.labelForName.backgroundColor = [UIColor redColor];
    self.labelForName.text = self.model.name;
    self.labelForName.textColor = [UIColor whiteColor];
    self.labelForName.font = [UIFont boldSystemFontOfSize:18];
    
    self.imageForLike = [[UIImageView alloc] init];
    [self addSubview:self.imageForLike];
    
    [self.imageForLike mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(self.headerImage).equalTo(@(20 * WIDGHTT));
        make.top.mas_equalTo(self.labelForName.mas_bottom).equalTo (@(5 * HEIGHTT));
        make.width.mas_equalTo(20 * WIDGHTT);
        make.height.mas_equalTo(self.imageForLike.mas_width).multipliedBy(1. / 1.);
        
    }];
    self.imageForLike.image = [UIImage imageNamed:@"iconfont-xin-1"];
    
    self.labelForNumber = [[UILabel alloc] init];
    [self addSubview:self.labelForNumber];
    self.labelForNumber.textColor = [UIColor whiteColor];
    self.labelForNumber.font = [UIFont boldSystemFontOfSize:16];
    
    [self.labelForNumber mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(self.imageForLike.mas_right).equalTo(@(5 * WIDGHTT));
        make.centerY.equalTo(self.imageForLike.mas_centerY);
        make.width.mas_equalTo(50 * WIDGHTT);
        make.height.mas_equalTo(self.imageForLike.mas_width).multipliedBy(1. / 1.);
        
        
    }];
    
    if (self.model.followCount >= 10000) {
        
        self.labelForNumber.text = [NSString stringWithFormat:@"%.1f万",round(self.model.followCount) / 10000];
        
    } else {
    
        self.labelForNumber.text = [NSString stringWithFormat:@"%ld", (long)self.model.followCount];
    
    }
    
    self.imageForComment = [[UIImageView alloc] init];
    [self addSubview:self.imageForComment];
    
    [self.imageForComment mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(self.labelForNumber.mas_right).equalTo(@(10 * WIDGHTT));
         make.centerY.equalTo(self.imageForLike.mas_centerY);
        make.width.mas_equalTo(20 * WIDGHTT);
        make.height.mas_equalTo(self.imageForLike.mas_width).multipliedBy(1. / 1.);
    }];
    
    self.imageForComment.image = [UIImage imageNamed:@"iconfont-pinglun01"];

    self.labelForComment = [[UILabel alloc] init];
    [self addSubview:self.labelForComment];
    
    [self.labelForComment mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(self.imageForComment.mas_right).equalTo(@(5 * WIDGHTT));
        make.centerY.equalTo(self.imageForLike.mas_centerY);
        make.width.mas_equalTo(50 * WIDGHTT);
        make.height.mas_equalTo(self.imageForLike.mas_width).multipliedBy(1. / 1.);
        
    }];
    
    self.labelForComment.text = [NSString stringWithFormat:@"%ld", (long)self.model.commentCount];
    self.labelForComment.textColor = [UIColor whiteColor];
    self.labelForComment.font = [UIFont boldSystemFontOfSize:16];
    

}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
